// 2013-7-29下午06:00:55  net.betou.trade.main.dao.impl.NoticeDaoImpl.java

package net.betou.trade.main.dao.impl;

import net.betou.common.hibernate3.Finder;
import net.betou.common.hibernate3.HibernateBaseDao;
import net.betou.common.page.Pagination;
import net.betou.trade.entity.main.Video;
import net.betou.trade.main.dao.VideoDao;

import org.springframework.stereotype.Repository;

/**
 * 
 * @author 叶装装
 */
@Repository
public class VideoDaoImpl extends HibernateBaseDao< Video, Integer > implements VideoDao{

	public Video deleteById( Integer id ) {
		Video bean = get( id );
		if( bean != null ){
			getSession( ).delete( bean );
		}
		
		return bean;
	}

	public Video findById( Integer id ) {
		return get( id );
	}

	public Video findMyVideo( Integer id, Integer selfId ) {
		String hql = "from Video bean where bean.id=? and bean.admin.id=?";
		return ( Video ) findUnique( hql, id, selfId ); 
	}

	public Pagination getPage( Integer selfId, String searchProperty, String searchValue, String orderProperty, String orderDirection, int pageNo, int pageSize ) {
		Finder f = Finder.create( " from Video bean where 1=1 " );
		if( selfId != null ){
			f.append( " and bean.admin.id=:id" );
			f.setParam( "id", selfId );
			
		}
		
		createSearch( f, searchProperty, searchValue );
		createOrder( f, orderProperty, orderDirection, "id" );
		
		return find( f, pageNo, pageSize );
	}

	public Video save( Video bean ) {
		getSession( ).save( bean );
		return bean;
	}

	@Override
	protected Class< Video > getEntityClass( ) {
		return Video.class;
	}
}
